home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / A.D. Software / OOFILE / OOFILE AppMaker / FileAndFind / Pre-built version, as generated / CFileAndFindDoc.cp < prev    next >
Text File  |  1996-03-21  |  4KB  |  202 lines

  1. // CFileAndFindDoc.cp -- Document methods
  2. // Created 21/3/96 12:09 by AppMaker
  3.  
  4. #include "CFileAndFindDoc.h"
  5.  
  6. #include "FileAndFind_OOFILE.h"
  7. #include "CEditArticle.h"
  8. #include "CEditArticle.h"
  9.  
  10. #include "CListArticles.h"
  11. #include "CmdCodes.h"
  12.  
  13. #include <LFile.h>
  14. #include <LPlaceHolder.h>
  15. #include <LPrintout.h>
  16. #include <LWindow.h>
  17. #include <UWindows.h>
  18. #include <String_Utils.h>
  19.  
  20. const ResIDT    prto_PrintView        = 201;
  21. const ResIDT    STRx_Untitled        = 128;
  22.  
  23. // ---------------------------------------------------------------------------
  24. //        • CFileAndFindDoc
  25. // ---------------------------------------------------------------------------
  26.  
  27. CFileAndFindDoc::CFileAndFindDoc(
  28.     LCommander    *inSuper)
  29.         : LSingleDoc(inSuper)
  30. , mData(0)
  31. , mArticles(0)
  32. {
  33. }
  34.  
  35. // ---------------------------------------------------------------------------
  36. //        • ~CFileAndFindDoc
  37. // ---------------------------------------------------------------------------
  38. //    Destructor
  39. //
  40.  
  41. CFileAndFindDoc::~CFileAndFindDoc()
  42. {
  43.     delete mData;
  44. delete mArticles;
  45. }
  46.  
  47. //----------
  48. void
  49. CFileAndFindDoc::newFile()
  50. {
  51. FSSpec    fileSpec;
  52. if (AskSaveAs(fileSpec, true)) {
  53. MakeDatabaseObjects();
  54. mData->newConnection(OOF_MacString(fileSpec.name));
  55. CompleteOpenFile(&fileSpec);
  56. }
  57. }
  58.  
  59. //----------
  60. void
  61. CFileAndFindDoc::openFile(
  62.     FSSpec        *inFileSpec)
  63. {
  64. MakeDatabaseObjects();
  65. mData->openConnection(OOF_MacString(inFileSpec->name));
  66. CompleteOpenFile(inFileSpec);
  67. }
  68.  
  69.  
  70.  
  71. // ---------------------------------------------------------------------------
  72. //        • DoPrint
  73. // ---------------------------------------------------------------------------
  74. //    Print the contents of the Document
  75.  
  76. void
  77. CFileAndFindDoc::DoPrint()
  78. {
  79.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  80.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  81.                                     thePrintout->FindPaneByID('TBox');
  82. //!    textPlace->InstallOccupant(mTextView, atNone);
  83.  
  84.  
  85.     thePrintout->DoPrintJob();
  86.     delete thePrintout;
  87. }
  88.  
  89. //----------
  90. void
  91. CFileAndFindDoc::DoAddArticleLocation ()
  92. {
  93. }
  94.  
  95. //----------
  96. void
  97. CFileAndFindDoc::DoDelArticleLocation ()
  98. {
  99. }
  100.  
  101. //----------
  102. Boolean
  103. CFileAndFindDoc::ObeyCommand(
  104.     CommandT    inCommand,
  105.     void        *ioParam)
  106. {
  107.     Boolean        cmdHandled = true;
  108.  
  109.     switch (inCommand) {
  110.  
  111.     // +++ Add cases here for the commands you handle
  112.     //        Remember to add same cases to FindCommandStatus below
  113.     //        to enable/disable the menu items for the commands
  114.  
  115.  
  116.     case cmdAddArticleLocation:
  117.         DoAddArticleLocation ();
  118.         break;
  119.  
  120.     case cmdDelArticleLocation:
  121.         DoDelArticleLocation ();
  122.         break;
  123.  
  124.     default:
  125.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  126.         break;
  127.     }
  128.  
  129.     return cmdHandled;
  130. }
  131.  
  132. //----------
  133. void
  134. CFileAndFindDoc::FindCommandStatus(
  135.     CommandT    inCommand,
  136.     Boolean        &outEnabled,
  137.     Boolean        &outUsesMark,
  138.     Char16        &outMark,
  139.     Str255        outName)
  140. {
  141.     outUsesMark = false;
  142.  
  143.     switch (inCommand) {
  144.  
  145.     // +++ Add cases here for the commands you handle
  146.  
  147.     case cmdAddArticleLocation:
  148.         outEnabled = true;
  149.         break;
  150.     case cmdDelArticleLocation:
  151.         outEnabled = true;
  152.         break;
  153.  
  154.     default:
  155.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  156.                                             outUsesMark, outMark, outName);
  157.         break;
  158.     }
  159. }
  160. //----------
  161. void
  162. CFileAndFindDoc::MakeDatabaseObjects()
  163. {
  164.  
  165. // MUST TAKE PLACE BEFORE newConnection or openConnection
  166. // you can't define dbTables after opening the connection
  167.  
  168. // Note if these were defined as part of CFIleAndFindDoc, instead of being
  169. // 'newed' heap-based objects, this method would not be necessary
  170.  
  171. mData = new dbConnect_ctree;
  172. // create all database tables
  173. mArticles = new CdbArticles;
  174.  
  175. // change types of files created by c-tree (given modification to ctclib.c)
  176. ctMacCreator = kSignature;
  177. ctMacType = kFileType;
  178. }
  179.  
  180.  
  181. //----------
  182. void
  183. CFileAndFindDoc::CompleteOpenFile(
  184. FSSpec        *inFileSpec)
  185. {
  186.  
  187. // can now make the factories for our database editing windows and dialogs
  188. // which require us to have constructed the database objects
  189.  
  190. AdoptAddDialogFactory(new CEditArticleFactory(this, mArticles));
  191. AdoptEditDialogFactory(new CEditArticleFactory(this, mArticles));
  192. AdoptBrowseWindowFactory(new CListArticlesFactory(this, mArticles));
  193.  
  194. mWindow = MakeBrowser();
  195. if (mWindow != nil) {
  196.     mWindow->SetDescriptor (inFileSpec->name);
  197. }
  198. mIsSpecified = true;
  199.  
  200. }
  201.  
  202.